package o;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableContainer;
import android.graphics.drawable.DrawableContainer.DrawableContainerState;
import android.graphics.drawable.InsetDrawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.util.Log;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.lang.reflect.Method;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public final class gg {
    private static Method ˊ;
    private static boolean ˋ;
    private static Method ˎ;
    private static boolean ॱ;

    @Deprecated
    public static void ˎ(@NonNull Drawable drawable) {
        drawable.jumpToCurrentState();
    }

    public static void ˏ(@NonNull Drawable drawable, boolean z) {
        if (VERSION.SDK_INT >= 19) {
            drawable.setAutoMirrored(z);
        }
    }

    public static boolean ˊ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 19) {
            return drawable.isAutoMirrored();
        }
        return false;
    }

    public static void ˋ(@NonNull Drawable drawable, float f, float f2) {
        if (VERSION.SDK_INT >= 21) {
            drawable.setHotspot(f, f2);
        }
    }

    public static void ˏ(@NonNull Drawable drawable, int i, int i2, int i3, int i4) {
        if (VERSION.SDK_INT >= 21) {
            drawable.setHotspotBounds(i, i2, i3, i4);
        }
    }

    public static void ॱ(@NonNull Drawable drawable, @ColorInt int i) {
        if (VERSION.SDK_INT >= 21) {
            drawable.setTint(i);
        } else if (drawable instanceof gf) {
            ((gf) drawable).setTint(i);
        }
    }

    public static void ॱ(@NonNull Drawable drawable, @Nullable ColorStateList colorStateList) {
        if (VERSION.SDK_INT >= 21) {
            drawable.setTintList(colorStateList);
        } else if (drawable instanceof gf) {
            ((gf) drawable).setTintList(colorStateList);
        }
    }

    public static void ˋ(@NonNull Drawable drawable, @NonNull Mode mode) {
        if (VERSION.SDK_INT >= 21) {
            drawable.setTintMode(mode);
        } else if (drawable instanceof gf) {
            ((gf) drawable).setTintMode(mode);
        }
    }

    public static int ˏ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 19) {
            return drawable.getAlpha();
        }
        return 0;
    }

    public static void ˎ(@NonNull Drawable drawable, @NonNull Theme theme) {
        if (VERSION.SDK_INT >= 21) {
            drawable.applyTheme(theme);
        }
    }

    public static boolean ˋ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 21) {
            return drawable.canApplyTheme();
        }
        return false;
    }

    public static ColorFilter ॱ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 21) {
            return drawable.getColorFilter();
        }
        return null;
    }

    public static void ʽ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 23) {
            drawable.clearColorFilter();
        } else if (VERSION.SDK_INT >= 21) {
            drawable.clearColorFilter();
            if (drawable instanceof InsetDrawable) {
                ʽ(((InsetDrawable) drawable).getDrawable());
            } else if (drawable instanceof gd) {
                ʽ(((gd) drawable).ˏ());
            } else if (drawable instanceof DrawableContainer) {
                DrawableContainerState drawableContainerState = (DrawableContainerState) ((DrawableContainer) drawable).getConstantState();
                if (drawableContainerState != null) {
                    int childCount = drawableContainerState.getChildCount();
                    for (int i = 0; i < childCount; i++) {
                        Drawable child = drawableContainerState.getChild(i);
                        if (child != null) {
                            ʽ(child);
                        }
                    }
                }
            }
        } else {
            drawable.clearColorFilter();
        }
    }

    public static void ˎ(@NonNull Drawable drawable, @NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Theme theme) throws XmlPullParserException, IOException {
        if (VERSION.SDK_INT >= 21) {
            drawable.inflate(resources, xmlPullParser, attributeSet, theme);
        } else {
            drawable.inflate(resources, xmlPullParser, attributeSet);
        }
    }

    public static Drawable ʻ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 23) {
            return drawable;
        }
        if (VERSION.SDK_INT >= 21) {
            if (drawable instanceof gf) {
                return drawable;
            }
            return new gm(drawable);
        } else if (drawable instanceof gf) {
            return drawable;
        } else {
            return new ge(drawable);
        }
    }

    public static <T extends Drawable> T ॱॱ(@NonNull Drawable drawable) {
        if (drawable instanceof gd) {
            return ((gd) drawable).ˏ();
        }
        return drawable;
    }

    public static boolean ˏ(@NonNull Drawable drawable, int i) {
        if (VERSION.SDK_INT >= 23) {
            return drawable.setLayoutDirection(i);
        }
        if (VERSION.SDK_INT < 17) {
            return false;
        }
        if (!ॱ) {
            try {
                ˎ = Drawable.class.getDeclaredMethod("setLayoutDirection", new Class[]{Integer.TYPE});
                ˎ.setAccessible(true);
            } catch (Throwable e) {
                Log.i("DrawableCompat", "Failed to retrieve setLayoutDirection(int) method", e);
            }
            ॱ = true;
        }
        if (ˎ != null) {
            try {
                ˎ.invoke(drawable, new Object[]{Integer.valueOf(i)});
                return true;
            } catch (Throwable e2) {
                Log.i("DrawableCompat", "Failed to invoke setLayoutDirection(int) via reflection", e2);
                ˎ = null;
            }
        }
        return false;
    }

    public static int ᐝ(@NonNull Drawable drawable) {
        if (VERSION.SDK_INT >= 23) {
            return drawable.getLayoutDirection();
        }
        if (VERSION.SDK_INT < 17) {
            return 0;
        }
        if (!ˋ) {
            try {
                ˊ = Drawable.class.getDeclaredMethod("getLayoutDirection", new Class[0]);
                ˊ.setAccessible(true);
            } catch (Throwable e) {
                Log.i("DrawableCompat", "Failed to retrieve getLayoutDirection() method", e);
            }
            ˋ = true;
        }
        if (ˊ != null) {
            try {
                return ((Integer) ˊ.invoke(drawable, new Object[0])).intValue();
            } catch (Throwable e2) {
                Log.i("DrawableCompat", "Failed to invoke getLayoutDirection() via reflection", e2);
                ˊ = null;
            }
        }
        return 0;
    }
}
